Skip to content

IconBrowser

Base classes

Name Children Inherits
MainWindow
prettyqt.widgets.mainwindow
Main application window.

⋔ Inheritance diagram

graph TD
  85454427["custom_widgets.IconBrowser"]
  2142163847["widgets.MainWindow"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  3332481379["QtWidgets.QMainWindow"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  2142163847 --> 85454427
  829357528 --> 2142163847
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  3332481379 --> 2142163847
  3620195106 --> 3332481379
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: MainWindow

A small browser window that allows the user to search through all icons.

You can also copy the name and python code for the currently selected icon.

Source code in prettyqt/custom_widgets/iconbrowser.py
class IconBrowser(widgets.MainWindow):
    """A small browser window that allows the user to search through all icons.

    You can also copy the name and python code for the currently selected icon.
    """

    def __init__(self):
        super().__init__()
        self.setMinimumSize(500, 500)
        self.set_title("Icon Browser")
        font_maps = {k: v.charmap for k, v in iconprovider._instance().fonts.items()}
        icon_names = [
            f"{font_collection}.{icon_name}"
            for font_collection, font_data in font_maps.items()
            for icon_name in font_data
        ]
        model = IconModel(icon_color="text_role")
        model.setStringList(sorted(icon_names))

        self._proxy_model = itemmodels.FuzzyFilterProxyModel()
        self._proxy_model.setSourceModel(model)
        self._proxy_model.set_filter_case_sensitive(True)
        self._proxy_model.set_match_color(None)

        self._listview = widgets.ListView(
            self,
            uniform_item_sizes=True,
            view_mode="icon",
            context_menu_policy="custom",
            double_clicked=self._copy_icon_text,
            vertical_scroll_bar_policy="always_on",
        )
        eventfilter = listviewgridresizeeventfilter.ListViewGridResizeEventFilter(
            parent=self._listview
        )
        self._listview.installEventFilter(eventfilter)
        self._listview.set_model(self._proxy_model)

        self._lineedit = widgets.LineEdit(
            parent=self, text_changed=self._trigger_instant_update
        )

        self._combobox = widgets.ComboBox(
            parent=self,
            minimum_width=75,
            current_index_changed=self._trigger_instant_update,
        )
        self._combobox.addItems([ALL_COLLECTIONS, *sorted(font_maps.keys())])

        search_bar_frame = widgets.Frame(self)
        layout = search_bar_frame.set_layout("horizontal", margin=0)
        layout.add(self._combobox)
        layout.add(self._lineedit)

        self._copy_button = widgets.PushButton("Copy Name", clicked=self._copy_icon_text)
        frame = widgets.Frame(self)
        layout = frame.set_layout("vertical")
        layout.add(search_bar_frame)
        layout.add(self._listview)
        layout.add(self._copy_button)
        self.setCentralWidget(frame)
        self.add_shortcut("return", callback=self._copy_icon_text)
        self._lineedit.setFocus()
        self.position_on("screen")

    def _trigger_instant_update(self):
        """Stop timer used for committing search term and update proxy model instantly."""
        self._proxy_model.set_search_term(self._lineedit.text())

    def _copy_icon_text(self):
        """Copy the name of the currently selected icon to the clipboard."""
        if indexes := self._listview.selectedIndexes():
            widgets.Application.copy_to_clipboard(indexes[0].data())

:fa-brands-github: Show source on GitHub